package com.yuzhi.master.water.service.impl;

import com.yuzhi.common.contant.CacheNames;
import com.yuzhi.common.util.redis.CacheUtils;
import com.yuzhi.master.water.domain.GzzhSewageStatistics;
import com.yuzhi.master.water.mapper.GzzhSewageStatisticsMapper;
import com.yuzhi.master.water.service.ISeWageWaterStatisticsService;
import com.yuzhi.system.service.StationService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 测站基础信息Service业务层处理
 * @author auto code generator
 * @date 2024-04-12
 */
@RequiredArgsConstructor
@Service
public class SeWageWaterStatisticsServiceImpl implements ISeWageWaterStatisticsService,StationService {


    private final GzzhSewageStatisticsMapper gzzhSewageStatisticsMapper;

    @Override
    public List<GzzhSewageStatistics> selectListInfo()
    {

        List<GzzhSewageStatistics>  list  =  gzzhSewageStatisticsMapper.selectList();

        return  list;

    }


    /**
     * 将污水统计信息加载到缓存中
     */
    @Override
    public  void loadingSewageCache () {

        List<GzzhSewageStatistics>  list  =  gzzhSewageStatisticsMapper.selectList();
        if(list!=null && !list.isEmpty())
        {
            GzzhSewageStatistics  ss  = list.get(0);
            //污水厂数量
            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS,"sewageFactoryNum", ss.getSewageFactoryNum()==null?0:ss.getSewageFactoryNum());
            //污水分区数量
            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS, "sewageDistrictNum", ss.getSewageDistrictNum()==null?0:ss.getSewageDistrictNum());
            //污水泵站数量
            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS, "sewagePumpNum", ss.getSewagePumpNum()==null?0:ss.getSewagePumpNum());
            //排水分区数量
            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS, "drainageDistrictNum", ss.getDrainageDistrictNum()==null?0:ss.getDrainageDistrictNum());
            //管网长度=雨水管网+污水管网
            BigDecimal  sewagePipeLength  = BigDecimal.valueOf(ss.getSewagePipeLength()==null?0:ss.getSewagePipeLength());
            BigDecimal  rainPipeLength = BigDecimal.valueOf(ss.getRainPipeLength()==null?0:ss.getRainPipeLength());
            // 7.14 (客户)修改计算规则  只要污水管网
            BigDecimal pipeLength  = sewagePipeLength ;
            // 转换为公里（除以1000），并保留2位小数
            BigDecimal pipeLengthInKilometers = pipeLength.divide(
                    BigDecimal.valueOf(1000),
                    2,
                    RoundingMode.HALF_UP  // 使用四舍五入
            );

            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS, "pipeLength", pipeLengthInKilometers);

            //污水干管
            BigDecimal sewageDuctLength  = BigDecimal.valueOf(ss.getSewageDuctLength()==null?0:ss.getSewageDuctLength());
            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS, "sewageDuctLength", sewageDuctLength);

            //排水户数量
            CacheUtils.put(CacheNames.GZZH_SEWAGE_STATISTICS,"clientNum", ss.getClientNum()==null?0:ss.getClientNum());

        }

    }


    @Override
    public void loadingInfoCache() {

    }

    @Override
    public void loadingPumpCache() {
    }

    @Override
    public void loadingIrRdCache() {

    }
}
